package com.subfg.common.i18.constant;

import com.subfg.common.util.common.StringUtil;

public enum LanguageConstant {
    ENGLISH(0, "en", "US", "en_US"),
    CHINESE(1, "zh", "CN", "zh_CN")
    ;

    private Integer id;
    private String language;
    private String region;
    private String concatLangugae;

    LanguageConstant(Integer id, String language, String region, String concatLangugae) {
        this.id = id;
        this.language = language;
        this.region = region;
        this.concatLangugae = concatLangugae;
    }

    public String getLanguage() {
        return language;
    }

    public Integer getId() {
        return id;
    }

    public String getRegion() {
        return region;
    }


    public String getConcatLangugae() {
        return concatLangugae;
    }

    /**
     * 系统支持的语言类型
     * @param languageType              前台传过来的语言类型
     * @return                          返回
     */
    public static LanguageConstant systemSupportLanguage(Integer languageType){
        if (languageType != null) {
            for (LanguageConstant languageConstant : values()) {
                if (languageType.equals(languageConstant.getId())) {
                    return languageConstant;
                }
            }
        }
        // 返回默认请求语言
        return LanguageConstant.CHINESE;
    }

    public static LanguageConstant systemSupportLanguageConcat(String concatLangugae) {
        if (!StringUtil.isEmpty(concatLangugae)) {
            for (LanguageConstant languageConstant : values()) {
                if (concatLangugae.equals(languageConstant.getConcatLangugae())) {
                    return languageConstant;
                }
            }
        }
        return LanguageConstant.ENGLISH;
    }
 }
